package com.hwz.common.exception;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author: hwz
 * @CreateTime: 2025-06-02
 */


public class ListValueValidator  implements ConstraintValidator<ListValueValid, Integer> {

    private Set< Integer> values = new HashSet<>();
    @Override
    public void initialize(ListValueValid constraintAnnotation) {
        Arrays.stream(constraintAnnotation.vales()).forEach( value -> values.add(value));
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
         if (values.contains(value)) {
            return true;
        }
        return false;
    }
}
